package com.sanjin.utils;


import com.sanjin.enums.ResponseEnum;
import com.sanjin.vo.ResponseVo;
import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;

/**
 * @description:
 * @author: sanjin
 * @date: 2019/4/2 20:41
 */
public class ResponseVoUtils {
    public static ResponseVo success(Object data) {
        ResponseVo responseVo = new ResponseVo();
        responseVo.setCode(ResponseEnum.OK.getCode());
        responseVo.setMessage(ResponseEnum.OK.getMessage());
        responseVo.setData(data);
        return responseVo;
    }

    public static ResponseVo success() {
        return success(null);
    }


    public static ResponseVo error(ResponseEnum responseEnum) {
        ResponseVo responseVo = new ResponseVo();
        responseVo.setCode(responseEnum.getCode());
        responseVo.setMessage(responseEnum.getMessage());
        responseVo.setData(responseEnum.getMessage());
        return responseVo;
    }

    /**
     *
     * @param responseEnum 业务逻辑错误
     * @param detail 错误详细信息
     * @return
     */
    public static ResponseVo error(ResponseEnum responseEnum, String detail) {
        ResponseVo responseVo = new ResponseVo();
        responseVo.setCode(responseEnum.getCode());
        responseVo.setMessage(detail);
        responseVo.setData(detail);
        return responseVo;
    }

    /**
     * code 默认为错误code 0，没有业务逻辑错误代码
     * @param detail 错误详细信息
     * @return
     */
    public static ResponseVo error(String detail) {
        ResponseVo responseVo = new ResponseVo();
        responseVo.setCode(ResponseEnum.ERROR.getCode());
        responseVo.setMessage(detail);
        responseVo.setData(detail);
        return responseVo;
    }

}
